package com.hgw.Demo06_CompositePattern.Exercises11_7_5;

import java.util.ArrayList;

/**
 * Data time:2021/12/15 16:58
 * StudentID:2019112118
 * Author:hgw
 * Description: 办公室，充当容器构建角色
 */
public class Office extends AbstractFile{

    private ArrayList<AbstractFile> list = new ArrayList<AbstractFile>();
    private String name;

    public Office(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile file) {
        list.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        list.remove(file);
    }

    @Override
    public AbstractFile getChild(int i) {
        return list.get(i);
    }

    @Override
    public void operation() {
        System.out.println("--" + name);
        // 从容器构建具体业务方法的实现，将递归调用成员构建的业务方法
        for (AbstractFile abstractFile : list) {
            abstractFile.operation();
        }
    }
}
